package com.basketball.gym.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.basketball.gym.pojo.ResponseData;
import com.basketball.gym.pojo.User;
import com.basketball.gym.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员的用户管理")
@RestController
@PreAuthorize("hasAnyRole('admin','superAdmin')")
@RequestMapping("/gym/admin/user")
public class AdminUserController {
    @Autowired
    private AdminUserService adminUserService;

    @ApiOperation("查询用户列表（分页,可通过id，phone,state）")
    @GetMapping
    public ResponseData<IPage<User>> getUserList(User user) {
        return adminUserService.getUserList(user);
    }

    @ApiOperation("修改用户信息")
    @PutMapping
    public ResponseData<User> updateUser(@Validated(User.update.class) @RequestBody User user) {
        return adminUserService.updateUser(user);
    }


    @ApiOperation("通过手机号查询用户")
    @GetMapping("/phone")
    public ResponseData<User> getUserByPhone(String phone){
        return adminUserService.getUserByPhone(phone);
    }
}
